<?php
class User_model extends Model {

    function User_model()
    {
        parent::Model();
        $this->load->database();
    }

    /**
     * Cheack Credintials
     *
     * this cheacks the users log in information against the database and
     * returns false if it does not or the users user id if it matches
     *
     * @param string $name
     * @param string $pass
     * @return int(UID) if true or FALSE is false
     */
    function check_cred($name,$pass)
    {
        $this->load->library('encrypt');

        $query = $this->db->get_where('user', "`Name` = '$name'");

            if ($query->num_rows() == 1)
            {
                $pass = $this->encrypt->sha1($pass);
                $result = $query->row();
                    if ($result->Password == $pass)
                            return $result->UID;
                    else
                            return FALSE;
            }
            else
                    return FALSE;
    }

    /**
     * retrive user
     *
     * gets a user row from the database where the user id is equal to
     * $user_id
     *
     * @param int $user_id
     * @return array or FALSE
     */
        function retrieve_user($user_id)
        {
                $result = $this->db->get_where('user', array('UID' => $user_id));

                if ($result->num_rows() == 1)
                        return $result->row();
                else
                        return FALSE;
        }


}